
import 'package:valovault_reminder/common/config/val_assets_name.dart';
import 'package:valovault_reminder/pages/base/val_app_common_bar.dart';
import 'package:valovault_reminder/pages/base/val_base_ui_page.dart';
import 'package:valovault_reminder/pages/home/models/val_post_record_model.dart';
import 'package:valovault_reminder/util/val_screen_size_kit.dart';
import 'package:flutter/material.dart';

import '../../util/val_eventbus_manager.dart';

class ValNoticeWorkPage extends StatefulWidget {
  final ValPostRecordModel postModel;
  const ValNoticeWorkPage({super.key, required this.postModel});

  @override
  State<ValNoticeWorkPage> createState() => _ValNoticeWorkPageState();
}

class _ValNoticeWorkPageState extends ValBaseUIPageState<ValNoticeWorkPage> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    isAppBar = false;
    extendBodyBehindAppBar = true;
  }

  @override
  PreferredSizeWidget? get appBar {
    return ValAppCommonBar(
      backgroundColor: Colors.transparent,
      title: '',
      titleColor: Colors.white,
      brightness: Brightness.dark,
      leadingWidget: GestureDetector(
          onTap: () {
            // Navigator.of(context).pop();
          },
      ),
    );
  }

  Widget createTextContentElement(String content) {
    return  Container(
      height: 49,
      margin: const EdgeInsets.only(left: 24, right: 24, bottom: 10),
      padding: const EdgeInsets.only(left: 20, right: 20),
      alignment: Alignment.centerLeft,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20),
        border: Border.all(width: 1, style: BorderStyle.solid, color: const Color(0xFFE8A229),),
        image: const DecorationImage(
            image: AssetImage('${ValAssetsName.ASSETS_Message}val_notice_work_content_ground.png'), fit: BoxFit.fill),
      ),
      child: Text(content,
        style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w500), overflow: TextOverflow.clip,),
    );
  }

  @override
  Widget buildBody(BuildContext context) {
    return Stack(
      children: [
        // 背景色
        Positioned(
          top: 0, left: 0, right: 0, bottom: 0,
          child: Container(
            decoration: const BoxDecoration(
              color: Color(0xFF080822),
              gradient: LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [
                  Color(0xFF143B42),
                  Color(0xFF080822),
                ],
              ),
            ),
          ),
        ),

        // 顶部图片
        Positioned(
            top: ValScreenSizeKit.getInstance().statusBarHeight + 70, left: 0, right: 0, height: 250,
            child: Container(
              height: 250, width: 250,
              alignment: Alignment.center,
              decoration: const BoxDecoration(
                image: DecorationImage(
                    image: AssetImage('${ValAssetsName.ASSETS_Message}val_notice_work_content_icon.png'), fit: BoxFit.fitHeight),
              ),
            )
        ),

        // 文本
        Positioned(
          top: ValScreenSizeKit.getInstance().statusBarHeight + 70 + 250 + 60, left: 0, right: 0, bottom: 0,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              createTextContentElement('Name: ${widget.postModel.title}'),
              createTextContentElement('Amount: ${widget.postModel.followed}\$'),
              createTextContentElement('Due Date: ${widget.postModel.publishDate}'),
              GestureDetector(
                onTap: (){
                  widget.postModel.collected = true;
                  widget.postModel.saveToDb();
                  ValEventbusManager.getInstance().eventBus.fire('alarmDataUpdate');
                  Navigator.of(context).pop();
                },
                child: Container(
                  height: 49,
                  margin: const EdgeInsets.only(top: 29, left: 24, right: 24, bottom: 10),
                  padding: const EdgeInsets.only(left: 20, right: 20),
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(20),
                    gradient: const LinearGradient(
                      begin: Alignment.centerLeft,
                      end: Alignment.centerRight,
                      colors: [
                        Color(0xFFE8A229),
                        Color(0xFFF9C03D),
                        Color(0xFFFCCC41),
                      ],
                    ),
                  ),
                  child: const Text('Closure',
                    style: TextStyle(color: Color(0xFF333333), fontSize: 20, fontWeight: FontWeight.w500), overflow: TextOverflow.clip,),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
